import os
import json

class Path():
    '''
    初始化时获得本文件的绝对路径
    back（返回上级方式）:
    '''

    def __init__(self):
        fp = os.path.abspath(__file__)
        fp = fp.replace('\\', '/')
        ul_pos = fp[::-1].find('/')
        self.fp = fp[:len(fp)-ul_pos]
        # print(self.fp)

    def back(self, n=1):
        if n == 0:
            fp = self.fp
            ul_pos = fp.find('/')
            self.fp = fp[:ul_pos+1]
        else:
            for i in range(n):
                fp = self.fp
                ul_pos = fp[-2::-1].find('/')
                self.fp = fp[:len(fp) - ul_pos-1]
        return self.fp

    def isHere(self, filename):
        fp = self.fp + filename
        if not os.path.exists(fp):
            os.mkdir(fp)
            print('>新建文件夹：'+filename)
        self.fp = fp+'/'
        return self.fp

    def now(self):
        return os.listdir(self.fp)


class PathGod(Path):
    def ini(self):
        print(self.fp)
        self.fp_test = self.isHere('test')
        self.fp_Asset = self.isHere('Asset')
        self.back()
        self.fp_Head = self.isHere('Head')
        self.back()
        self.fp_Case = self.isHere('Case')
        self.back()
        self.fp_Data = self.isHere('Data')
        self.back()
        self.fp_FuncLogic = self.isHere('FuncLogic')
        self.back()
        return self.fp

    def down(self):
        lis = [x for x in dir(a) if 'fp' in x]
        dic = {}
        for i in lis:
            dic[i] = self.i
        dic['head'] = self.fp_head
        dic['path'] = self.fp
        dit = json.dumps(dic, sort_keys=False, indent=4, separators=(',', ': '))
        with open('path.json', 'w', encoding='utf-8') as ff:
            ff.write(dit)

    def inin(self):
        with open('path.json', 'r', encoding='utf-8') as ff:
            dic = json.load(ff)



a = PathGod()
a.ini()
print()
print(dir(a))